import { BroadCastCall } from "../broadCast/BroadCastCall";
import { MessageBlock } from "../../../../Framework/MQ/MessageBlock";
import { SBufferMsg } from "../../../../Message/Game/SBufferMsg";
import { SBuffer } from "../../../../Message/Public/SBuffer";
import { NetDispatcher } from "../../../mvc/core/NetDispatcher";
import { ServerCommand } from "../../mvc/ServerCommand";
import { Cache } from "../../cache/Cache";
import { EBufferOp } from "../../../../Message/Public/EBufferOp";
type int = number;
//class BuffCommand
    
    export  class BuffCommand extends BroadCastCall
    {
        constructor(arg1: Object)
        {
            super(arg1);
            return;
        }

        public /* override */ call(arg1: MessageBlock): void
        {
            super.call(arg1);
            var loc1=arg1.messageBase as SBufferMsg;
            var loc2=0;
            while (loc2 < loc1.buffers.length) 
            {
                this.updateRoleEntityInfoBuffer((loc1.buffers[loc2] as SBuffer).code, loc1.updateType);
                ++loc2;
            }
            _cache.buff.updateType = loc1.updateType;
            _cache.buff.sBufferMsg = loc1;
            NetDispatcher.dispatchCmd(ServerCommand.BufferUpdate, _cache.buff.buffInfoArray);
            return;
        }

        public updateRoleEntityInfoBuffer(arg1: int, arg2: int): void
        {
            var loc1=0;
            var loc2=null;
            var loc3=0;
            if (!(loc2 = Cache.instance.role.entityInfo).buffers) 
            {
                loc2.buffers = [];
            }
            var loc4=arg2;
            switch (loc4) 
            {
                case EBufferOp._EBufferOpAdd:
                {
                    loc2.buffers.push(arg1);
                    break;
                }
                case EBufferOp._EBufferOpRemove:
                {
                    loc1 = (loc3 = loc2.buffers.length - 1);
                    while (loc1 >= 0) 
                    {
                        if (loc2.buffers[loc1] == arg1) 
                        {
                            loc2.buffers.splice(loc1, 1);
                        }
                        --loc1;
                    }
                    break;
                }
            }
            return;
        }
    }
